package com.googlecode.animator.view.specialobjects
{
	import com.googlecode.animator.utils.MathUtils;
	
	import org.papervision3d.core.proto.MaterialObject3D;
	import org.papervision3d.core.render.data.RenderSessionData;
	import org.papervision3d.objects.DisplayObject3D;
	import org.papervision3d.objects.primitives.Plane;
    
    // http://hi-definitiontechnologies.com/viewtopic.php?f=28&t=7&sid=399c5223e3167b33005a99c2254b813b   
    // Hi-Definition Technologies Corp.
    // This is the base class for any Billboard type object. Although it looks incredibly simple, it is in fact the fastest possible method for creating 
    // any auto camera facing objects. And can be nested to any level of d03d
    // It can be the basis for any advanced Particle system that you can think of.
    // This billboard is an extention of Plane, so set it up and construct it exactly as you did for a Plane
    // Keep this class simple, and "extend" your functionality as you get more advanced with it.
    // This has been tested with creating fully operational Flash components with full interactivity.
    // So also makes for an excellent class to create menus/Gui's in 3D space without concern for orientation 
       
	public class BillBoard extends Plane 
	{	
		public function BillBoard(material:MaterialObject3D = null,width:Number = 0, height:Number = 0, segmentsW:Number = 0, segmentsH:Number = 0) 
		{
			super(material, width, height,segmentsW,segmentsH);
		}
		  
		// This is basically a lookAt function, and is capable of handling thousands of sprites/particles without breaking a sweat
		// This also handles any level of DO3D nesting, and plays 100% by the rules of Papervision projection.
		public override function project( parent:DisplayObject3D,  renderSessionData:RenderSessionData):Number 
		{
			MathUtils.copyAndTranspose(parent.world, transform, true);   // Perform the inversion, while also handling nested chains of DO3D
			transform.calculateMultiply3x3(transform, renderSessionData.camera.transform);
			return super.project(parent,renderSessionData);   // Finish up this projection chain with our new fixed up transform
		}
	}
}
